package cn.yanhu.kuwanapp.user

import androidx.lifecycle.MutableLiveData
import cn.woochen.comlib.BaseViewModel
import cn.yanhu.kuwanapp.bean.other.EditUserInfoBean
import cn.yanhu.kuwanapp.bean.request.ReqPhoneLoginBean
import cn.yanhu.kuwanapp.bean.response.*
import cn.yanhu.kuwanapp.http.status.BaseBean
import cn.yanhu.kuwanapp.http.status.ResultState
import cn.yanhu.kuwanapp.utils.ext.request
import cn.yanhu.kuwanapp.utils.ext.request2
import cn.yanhu.kuwanapp.utils.ext.rxApi

/**
 *
 * 类描述：
 * @author：woochen
 * create at：2021/7/25 1:20 PM
 */
class UserViewModel :BaseViewModel(){
    val sendCodeInfo  = MutableLiveData<ResultState<BaseBean<Any>>>()
    val wxloginInfo  = MutableLiveData<ResultState<RespWxLoginBean>>()
    val wxAuthInfo  = MutableLiveData<ResultState<Any>>()
    val phoneLoginInfo  = MutableLiveData<ResultState<RespLoginBean>>()
    val userInfoInfo  = MutableLiveData<ResultState<RespUserInfoBean>>()
    val myConfigInfo  = MutableLiveData<ResultState<RespMyConfigBean>>()
    val editUserInfoInfo  = MutableLiveData<ResultState<Any>>()

    //发送验证码
    fun sendCode(phone:String){
        request2({ rxApi.sendCode(phone) }, sendCodeInfo,true)
    }

    //微信登录
    fun wxlogin(wxCode:String,type:String){
        request({ rxApi.wxLogin(wxCode, type) }, wxloginInfo,true)
    }

    //微信登录
    fun wxAuth(wxCode:String,type:String){
        request({ rxApi.wxAuth(wxCode, type) }, wxAuthInfo,true)
    }

    //手机号登录
    fun phoneLogin(phone:String,code:String,wxUserInfo:String = ""){
        request({ rxApi.phoneLogin(ReqPhoneLoginBean(phone, code,wxUserInfo)) }, phoneLoginInfo,true)
    }

    //用户信息
    fun userInfo(source:String){
        request({ rxApi.userInfo(source) }, userInfoInfo,true)
    }

    //我的页面配置
    fun myConfig(){
        request({ rxApi.myConfig() }, myConfigInfo,true)
    }

    //更新用户信息
    fun editUserInfo(avatar:String,nickName:String){
        request({ rxApi.editUserInfo(EditUserInfoBean(avatar, nickName)) }, editUserInfoInfo,true)
    }


    val msgListInfo  = MutableLiveData<ResultState<List<RespMsgBean>>>()
    val readMsgInfo  = MutableLiveData<ResultState<BaseBean<Any>>>()
    val bindAlipayInfo  = MutableLiveData<ResultState<RespBindAlipayBean>>()
    val bindAlipayCallBackInfo  = MutableLiveData<ResultState<BaseBean<Any>>>()
    val withdrawRecordsInfo  = MutableLiveData<ResultState<RespWithdrawRecordBean>>()
    val taskListInfo  = MutableLiveData<ResultState<List<RespTaskListBean>>>()

    //消息列表
    fun msgList(endId:String,pageSize:Int){
        request({ rxApi.msgList(endId, pageSize) }, msgListInfo,true)
    }

    //读取消息
    fun readMsg(msgId:String){
        request2({ rxApi.readMsg(msgId) }, readMsgInfo,true)
    }

    val withdrawHomeInfo  = MutableLiveData<ResultState<RespWithdrawHomeBean>>()
    val withdrawInfo  = MutableLiveData<ResultState<BaseBean<Any>>>()

    //提现主页
    fun withdrawHome(){
        request({ rxApi.withdrawHome() }, withdrawHomeInfo,true)
    }

    //提现
    fun withdraw(money:String,payType:String){
        request2({ rxApi.withdraw(money, payType) }, withdrawInfo,true)
    }

    //绑定支付宝
    fun bindAlipay(){
        request({ rxApi.bindAlipay() }, bindAlipayInfo,true)
    }

    //绑定支付宝回调
    fun bindAlipayCallBack(result:String){
        request2({ rxApi.bindAlipayCallBack(result) }, bindAlipayCallBackInfo,true)
    }

    //提现记录
    fun withdrawRecords(type:Int,pageNo:Int,pageSize:Int){
        request({ rxApi.withdrawRecords(type, pageNo, pageSize) }, withdrawRecordsInfo,true)
    }
    
    //我的任务
    fun taskList(pageNo:Int){
        request({ rxApi.taskList( pageNo) }, taskListInfo,true)
    }
}